//
//  TXY_DateDownTools.m
//  UILesson17_DownLoad
//
//  Created by lanou3g on 15/10/29.
//  Copyright (c) 2015年 涂晓雨. All rights reserved.
//

#import "TXY_DateDownTools.h"

@implementation TXY_DateDownTools


+(void)downloadDataWithURL:(NSString *)urlString andMethod:(NSString *)method  andBoady:(NSString *)body  andBlock:(optionBlock)block
{
    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url];
    if ([method isEqualToString:@"POST"] || [method isEqualToString:@"post"]) {
        //添加post方式需要设置的东西
        [request setHTTPMethod:@"POST"];
        [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
    }
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        block(data);
    }];

}
@end
